package org.jeecg.modules.zhima.center.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.jeecg.modules.zhima.center.entity.PmsBrand;
import org.jeecg.modules.zhima.center.entity.SmsHomeBrand;
import org.jeecg.modules.zhima.center.mapper.SmsHomeBrandMapper;
import org.jeecg.modules.zhima.center.service.IPmsBrandService;
import org.jeecg.modules.zhima.center.service.ISmsHomeBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: sms_home_brand
 * @Author: jeecg-boot
 * @Date:   2020-08-27
 * @Version: V1.0
 */

@Service
public class SmsHomeBrandServiceImpl extends ServiceImpl<SmsHomeBrandMapper, SmsHomeBrand> implements ISmsHomeBrandService {

    @Autowired
    private IPmsBrandService brandService;

    @Override
    public List<PmsBrand> getList() {
        List<SmsHomeBrand> homeBrands = list(new LambdaQueryWrapper<SmsHomeBrand>().eq(SmsHomeBrand::getRecommendStatus, 1).orderByDesc(SmsHomeBrand::getSort));
        if (CollectionUtils.isNotEmpty(homeBrands)){
            List<Integer> ids = homeBrands.stream().map(SmsHomeBrand::getBrandId).collect(Collectors.toList());
            return brandService.getBrandByIds(ids);
        }
        return null;
    }
}
